
/**
 * @param {Context} context
 * @param {string} shaderName
 * @returns {Scene}
 */
function createScene(context, shaderName) {
  return new context.Scene({
    require : [],
    /*
     * 挂件
     */
    pendants : {
      shaders : null
    },

    init(libs) {
      // HTML
      handleDom();
  
      // 挂件
      this.loadPendant();
    },

    /* **********
     *   挂件   *
     ********** */

    loadPendant() {
      let self = this;
      context.createPendant('shaders/normal_glsl_canvas', {
        domName : 'content',
        shaderName,
      }).then(function (pendant) {
        self.pendants.shaders = pendant;
        self.pendants.shaders.sendStatus = function() {
          self.sendStatus();
        }
        self.pendants.shaders.sendStatus();
      })
    },

    onMessage(name, arg) {
      if (this.pendants.shaders != null) {
        this.pendants.shaders.onMessage(name, arg);
      }
    },

    collectInfo() {
      if (this.pendants.shaders != null) {
        return this.pendants.shaders.collectInfo();
      }
      return {
        loaded : false
      };
    },

  });
}

function handleDom() {
  let root = document.getElementById('main');

  let child = document.createElement('div');
  child.id = 'content';
  child.style.position = 'absolute';
  child.style.width = '100%';
  child.style.height = '100%';
  root.append(child);
}

export default createScene;
